﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A83单选答题
{
    class Program
    {
        static void Main(string[] args)
        {
            //准备题
            SingleQuestion[] singleQuestions = GetQuestions();
            //用户答案容器
            string[] userAnswer=new string[singleQuestions.Length];
            //答题
            for (int i = 0; i < singleQuestions.Length; i++)
            {
                SingleQuestion q=   singleQuestions[i];
                //显示题
                ShowQuestion(q);
                //获取用户输入的答案
                Console.WriteLine("请输入答案:");
                userAnswer[i] = Console.ReadLine();
                Console.Clear();
            }

            //统计分数
            int n = 0;
            for (int i = 0; i < singleQuestions.Length; i++)
            {
                if (singleQuestions[i].trueAnswer==userAnswer[i])
                {
                    n++;
                }
            }
            Console.WriteLine("你答对了{0}道题",n);


        }

        //获取题
        static SingleQuestion[] GetQuestions() 
        {
            //有可能是读文件,数据库,网络

            SingleQuestion[] singleQuestions =
               {
                new SingleQuestion(
                    "String是什么类型?",
                new string[]{
                    "A.值类型",
                    "B.引用类型",
                    "C.以上都是",
                    "D.未知类型" },
                "B"
                ),

                    new SingleQuestion(
                    "int多少位?",
                new string[]{
                    "A.8",
                    "B.16",
                    "C.32",
                    "D.64" },
                "C"
                ),

                    new SingleQuestion(
                    "以下哪一个选项不是数组的特点?",
                new string[]{
                    "A.长度不可变",
                    "B.存储的元素类型要相同",
                    "C.内存连续",
                    "D.以键值对形式存储" },
                "D"
                ),
          };

            return singleQuestions;
        }
        //控制台显示题
        static void ShowQuestion(SingleQuestion singleQuestion ) 
        {

            Console.WriteLine(singleQuestion.title);
            for (int i = 0; i < singleQuestion.options.Length; i++)
            {
                Console.WriteLine("    "+singleQuestion.options[i]);
            }
      
        }

    }
}
